package com.greenyoung.pwiki.uaa.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.greenyoung.pwiki.uaa.entity.PermissionEntity;
import com.greenyoung.pwiki.uaa.entity.UserEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Set;

/**
 * @author Mr.Zhao
 */
@Mapper
public interface UserDao extends BaseMapper<UserEntity> {
    /**
     * 通过用户id查询用户权限
     * @param userId 用户id
     * @return 用户权限实体集合
     */
    @Select("select *\n" +
            "from user_role\n" +
            "left join role_permission rp on user_role.role_id = rp.role_id\n" +
            "left join permission p on rp.permission_id = p.id\n" +
            "where user_id = #{userId};")
    Set<PermissionEntity> findPermissionsByUserId(Long userId);
}
